package com.jxwifi.cloud.quickcleanserver.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jxwifi.cloud.quickcleanserver.R;
import com.jxwifi.cloud.quickcleanserver.bean.WithdraApplyBean;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2019/5/15.
 */

public class RecordAdapter extends RecyclerView.Adapter {

    private PreferListItemClickListener mPreferItemClickListener;
    private Context mContext;
    private List<WithdraApplyBean> mList = new ArrayList<>();

    public RecordAdapter(Context ctx) {
        mContext = ctx;
    }

    /**
     * 下拉刷新时调用
     *
     * @param list
     */
    public void refresh(List<WithdraApplyBean> list) {
        mList.clear();
        addData(list);
    }

    public void updata() {
        mList.clear();
        notifyDataSetChanged();
    }

    //添加数据
    public void addData(List<WithdraApplyBean> list) {
        if (list.size() != 0 || list != null) {
            mList.addAll(list);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_pop_record_item, null);
        return new ViewHolder(view,mPreferItemClickListener);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ViewHolder mViewHolder = (ViewHolder) holder;
        final WithdraApplyBean mAskBean = mList.get(position);

        mViewHolder.mTvListPopRecordName.setText(mAskBean.getRealName());
        mViewHolder.mTvListPopRecordAccount.setText("账号："+mAskBean.getBankNum());
        mViewHolder.mTvListPopRecordBank.setText(mAskBean.getBankName());


    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        View mContainer;
        RelativeLayout mRelListPopRecord;
        TextView mTvListPopRecordName;//姓名
        TextView mTvListPopRecordAccount;//账号
        TextView mTvListPopRecordBank;//银行
        private PreferListItemClickListener mListener;

        public ViewHolder(View itemView,PreferListItemClickListener mPreferListener) {
            super(itemView);
            mContainer = itemView;
            mRelListPopRecord=(RelativeLayout)itemView.findViewById(R.id.rel_list_pop_record);
            mTvListPopRecordName = (TextView) itemView.findViewById(R.id.tv_list_pop_record_name);
            mTvListPopRecordAccount = (TextView) itemView.findViewById(R.id.tv_list_pop_record_account);
            mTvListPopRecordBank = (TextView) itemView.findViewById(R.id.tv_list_pop_record_bank);
            this.mListener = mPreferListener;
            mRelListPopRecord.setOnClickListener(this);
        }
        public void onClick(View v) {
            if (mListener != null) {
                mListener.onItemClick(v, getAdapterPosition());
            }
        }
    }

    /**
     * 创建一个回调接口
     */
    public interface PreferListItemClickListener {
        void onItemClick(View view, int position);
    }

    /**
     * 在activity里面adapter就是调用的这个方法,将点击事件监听传递过来,并赋值给全局的监听
     */
    public void setPreferListItemClickListener(PreferListItemClickListener mItemClickListener) {
        this.mPreferItemClickListener = mItemClickListener;
    }
}
